<template>
  <div class="invite-2-join">
    <header>
      <img class="logo" :src="adminImage" />
    </header>
    <div class="content-wrap">
      <div class="content-header">邀请加入</div>
      <div v-if="!successful" class="content-main invite-form">
        <div class="content-goal">
          <p class="goal-label">所属班级</p>
          <p class="goal-value">{{ targetName || '-' }}</p>
        </div>
        <div class="form-wrap">
          <a-form
            ref="formRef"
            :model="formState"
            layout="vertical"
            name="teacherForm"
            autocomplete="off"
            :rules="rules"
            @finish-failed="submit"
          >
            <a-form-item label="学生姓名" name="username">
              <a-input v-model:value="formState.username" v-trim :maxlength="50" placeholder="请输入学生姓名" />
            </a-form-item>

            <div class="flex gap-x-24">
              <a-form-item class="flex-1" label="学号" name="number">
                <a-input v-model:value="formState.number" v-trim :maxlength="20" placeholder="请输入学号" />
              </a-form-item>
              <a-form-item class="flex-1" label="手机号码" name="tel">
                <a-input v-model:value="formState.tel" v-trim :maxlength="11" placeholder="请输入手机号码" />
              </a-form-item>
            </div>

            <div class="btn-wrap">
              <a-button class="w-120" type="primary" html-type="submit" :loading="confirmLoading" @click="submit"> 提交 </a-button>
            </div>
          </a-form>
        </div>
      </div>

      <div v-else class="content-main status-success">
        <i class="iconfont icon-checkbox-circle-fill"></i>
        <p v-if="needCheck">申请提交成功，请耐心等待审核</p>
        <p v-else>信息录入成功，<span @click="$router.push('/login')">去登录</span></p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import adminImage from '@/assets/img/layout/admin-logo.svg'

  import { useForm } from '../hooks/use-form'

  const { successful, needCheck, targetName, formRef, formState, rules, submit, confirmLoading } = useForm()
</script>

<style lang="less" scoped>
  .invite-2-join {
    width: 100%;

    > header {
      display: flex;
      align-items: center;
      padding: 0 32px;
      height: 54px;
      background: #002b40;
      box-shadow: 0 1px 3px 0 rgba(37, 37, 45, 0.14), 0 2px 8px 0 rgba(37, 37, 45, 0.14);
    }

    .content-wrap {
      margin: 126px auto 0;
      width: 600px;
      background: #fff;
      border-radius: 8px;
      box-shadow: 0 1px 3px 0 rgba(37, 37, 45, 0.14), 0 2px 8px 0 rgba(37, 37, 45, 0.14);

      .content-header {
        height: 42px;
        font-size: 14px;
        text-align: center;
        color: rgba(21, 23, 27, 0.95);
        background: #fff;
        border-bottom: 1px solid #f5f5f5;
        font-weight: 700;
        line-height: 42px;
      }

      .content-main {
        &.invite-form {
          padding-bottom: 20px;

          .content-goal {
            display: flex;
            align-items: center;
            gap: 0 20px;
            padding: 8px 40px;
            margin-top: 40px;
            font-size: 14px;
            color: rgba(21, 23, 27, 0.95);
            background: rgba(0, 0, 0, 0.03);
            font-weight: 400;
            line-height: 22px;

            > p {
              flex-shrink: 0;
              flex-wrap: wrap;
            }

            .goal-value {
              flex: 1;
              text-align: end;
            }
          }

          .form-wrap {
            padding: 24px 40px 0;
          }

          .btn-wrap {
            display: flex;
            justify-content: center;
            margin-top: 60px;
          }
        }

        &.status-success {
          display: flex;
          justify-content: center;
          align-items: center;
          height: 442px;
          flex-direction: column;

          .iconfont {
            font-size: 36px;
            color: #4fb35b;
          }

          p {
            margin-top: 4px;
            font-size: 16px;
            color: rgba(21, 23, 27, 0.95);
            font-weight: 400;
            line-height: 24px;

            span {
              color: #009cf8;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
</style>
